package com.jsb.laundry.service.designpatterns.chainofresponsibility.orderservice.impl;

import java.util.List;

/**
 * 责任链模板
 */
public abstract class Handler {

    /**
     * 当前订单状态
     */
    public final int orderStatus;

    public Handler(int orderStatus) {
        this.orderStatus = orderStatus;
    }

    private Handler nextHandler;

    public void setNextHandler(Handler nextHandler) {
        this.nextHandler = nextHandler;
    }

    public Handler getNextHandler() {
        return nextHandler;
    }

    /**
     * 用了模板方法设计模式（非常经典的一种设计模式，优雅），即预设一定流程，留下钩子函数，用户自定义实现
     *
     */
    public void handle(Rider rider) {
        if (rider.getOrderStatus() == orderStatus) {
            handleHook(rider);
        }
        if (nextHandler != null) {
            nextHandler.handle(rider);
        } else {

        }
    }

    /**
     * 具体实现
     *
     */
    protected abstract List handleHook(Rider rider);
}
